package stack;
import java.util.Arrays;

public class MyStack {
    int[] array;
    int size;

    public MyStack() {
        array = new int[3];
    }

    public void push(int x) {
        ensureCapacity();
        array[size++] = x;
    }

    public void pop() {
        int e = peek();

        size--;
    }

    public int peek() {
        if(empty()) {
            throw new RuntimeException("栈为空，无法取出栈顶元素");
        }

        return array[size-1];
    }

    public boolean empty() {
        return size() == 0;
    }

    public int size() {
        return size;
    }
    public void ensureCapacity() {
        if(size == array.length) {
            array = Arrays.copyOf(array,size*2);
        }
    }

}
